<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Soap_Server - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.soap.server.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.soap.server.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.soap.html">Zend_Soap</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.soap.html">Zend_Soap</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.soap.client.html">Zend_Soap_Client</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.soap.server" class="section"><div class="info"><h1 class="title">Zend_Soap_Server</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Soap_Server</span> class is intended to simplify Web Services server
        part development for <acronym class="acronym">PHP</acronym> programmers.
    </p>

    <p class="para">
        It may be used in WSDL or non-WSDL mode, and using classes or functions to define Web
        Service <acronym class="acronym">API</acronym>.
    </p>

    <p class="para">
        When <span class="classname">Zend_Soap_Server</span> component works in the WSDL mode, it uses
        already prepared WSDL document to define server object behavior and transport layer options.
    </p>

    <p class="para">
        WSDL document may be auto-generated with functionality provided by <a href="zend.soap.autodiscovery.html#zend.soap.autodiscovery.introduction" class="link">Zend_Soap_AutoDiscovery component</a>
        or should be constructed manually using <a href="zend.soap.wsdl.html" class="link"><span class="classname">Zend_Soap_Wsdl</span> class</a> or any other
        <acronym class="acronym">XML</acronym> generating tool.
    </p>

    <p class="para">
        If the non-WSDL mode is used, then all protocol options have to be set using options
        mechanism.
    </p>

    <div class="section" id="zend.soap.server.constructor"><div class="info"><h1 class="title">Zend_Soap_Server constructor</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Soap_Server</span> constructor should be used a bit differently for
            WSDL and non-WSDL modes.
        </p>

        <div class="section" id="zend.soap.server.constructor.wsdl_mode"><div class="info"><h1 class="title">Zend_Soap_Server constructor for the WSDL mode</h1></div>
            

            <p class="para">
                <span class="classname">Zend_Soap_Server</span> constructor takes two optional parameters
                when it works in WSDL mode:

                <ol type="1">
                    <li class="listitem">
                        <p class="para">
                            <var class="varname">$wsdl</var>, which is an <acronym class="acronym">URI</acronym> of a WSDL
                            file

                            <a href="#fnid1" name="fn1"><sup>[1]</sup></a>
                                 <span class="methodname">setWsdl($wsdl)</span>
                            .
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            <var class="varname">$options</var> - options to create <acronym class="acronym">SOAP</acronym>
                            server object

                            <a href="#fnid2" name="fn2"><sup>[2]</sup></a>
                                 <span class="methodname">setOptions($options)</span>
                            .
                        </p>

                        <p class="para">
                            The following options are recognized in the WSDL mode:

                            <ul class="itemizedlist">
                                <li class="listitem">
                                    <p class="para">
                                        &#039;soap_version&#039; (&#039;soapVersion&#039;) - soap version to use
                                        (SOAP_1_1 or <acronym class="acronym">SOAP</acronym>_1_2).
                                    </p>
                                </li>

                                <li class="listitem">
                                    <p class="para">
                                        &#039;actor&#039; - the actor <acronym class="acronym">URI</acronym> for the server.
                                    </p>
                                </li>

                                <li class="listitem">
                                    <p class="para">
                                        &#039;classmap&#039; (&#039;classMap&#039;) which can be used to map some WSDL
                                        types to <acronym class="acronym">PHP</acronym> classes.
                                    </p>

                                    <p class="para">
                                        The option must be an array with WSDL types as keys and
                                        names of <acronym class="acronym">PHP</acronym> classes as values.
                                    </p>
                                </li>

                                <li class="listitem">
                                    <p class="para">
                                        &#039;encoding&#039; - internal character encoding (UTF-8 is always
                                        used as an external encoding).
                                    </p>
                                </li>

                                <li class="listitem">
                                    <p class="para">
                                        &#039;wsdl&#039; which is equivalent to
                                         <span class="methodname">setWsdl($wsdlValue)</span> call.
                                    </p>
                                </li>
                            </ul>
                        </p>
                    </li>
                </ol>
            </p>
        </div>

        <div class="section" id="zend.soap.server.wsdl_mode"><div class="info"><h1 class="title">Zend_Soap_Server constructor for the non-WSDL mode</h1></div>
            

            <p class="para">
                The first constructor parameter <em class="emphasis">must</em> be set to
                <b><tt>NULL</tt></b> if you plan to use <span class="classname">Zend_Soap_Server</span>
                functionality in non-WSDL mode.
            </p>

            <p class="para">
                You also have to set &#039;uri&#039; option in this case (see below).
            </p>

            <p class="para">
                The second constructor parameter (<var class="varname">$options</var>) is an array with
                options to create <acronym class="acronym">SOAP</acronym> server object

                <a href="#fnid3" name="fn3"><sup>[3]</sup></a>
                     <span class="methodname">setOptions($options)</span>
                .
            </p>

            <p class="para">
                The following options are recognized in the non-WSDL mode:

                <ul class="itemizedlist">
                    <li class="listitem">
                        <p class="para">
                            &#039;soap_version&#039; (&#039;soapVersion&#039;) - soap version to use (SOAP_1_1 or
                            <acronym class="acronym">SOAP</acronym>_1_2).
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            &#039;actor&#039; - the actor <acronym class="acronym">URI</acronym> for the server.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            &#039;classmap&#039; (&#039;classMap&#039;) which can be used to map some WSDL types to
                            <acronym class="acronym">PHP</acronym> classes.
                        </p>

                        <p class="para">
                            The option must be an array with WSDL types as keys and names of
                            <acronym class="acronym">PHP</acronym> classes as values.
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            &#039;encoding&#039; - internal character encoding (UTF-8 is always used as an
                            external encoding).
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            &#039;uri&#039; (required) - <acronym class="acronym">URI</acronym> namespace for
                            <acronym class="acronym">SOAP</acronym> server.
                        </p>
                    </li>
                </ul>
            </p>
        </div>
    </div>

    <div class="section" id="zend.soap.server.api_define_methods"><div class="info"><h1 class="title">Methods to define Web Service API</h1></div>
        

        <p class="para">
            There are two ways to define Web Service <acronym class="acronym">API</acronym> when your want to give
            access to your <acronym class="acronym">PHP</acronym> code through <acronym class="acronym">SOAP</acronym>.
        </p>

        <p class="para">
            The first one is to attach some class to the <span class="classname">Zend_Soap_Server</span>
            object which has to completely describe Web Service <acronym class="acronym">API</acronym>:
        </p>

        <pre class="programlisting brush: php">
...
class MyClass {
    /**
     * This method takes ...
     *
     * @param integer $inputParam
     * @return string
     */
    public function method1($inputParam) {
        ...
    }

    /**
     * This method takes ...
     *
     * @param integer $inputParam1
     * @param string  $inputParam2
     * @return float
     */
    public function method2($inputParam1, $inputParam2) {
        ...
    }

    ...
}
...
$server = new Zend_Soap_Server(null, $options);
// Bind Class to Soap Server
$server-&gt;setClass(&#039;MyClass&#039;);
// Bind already initialized object to Soap Server
$server-&gt;setObject(new MyClass());
...
$server-&gt;handle();
</pre>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Important!</b><br /></span>
            

            <p class="para">
                You should completely describe each method using method docblock if you plan to
                use autodiscover functionality to prepare corresponding Web Service WSDL.
            </p>
        </p></blockquote>

        <p class="para">
            The second method of defining Web Service <acronym class="acronym">API</acronym> is using set of
            functions and  <span class="methodname">addFunction()</span> or
             <span class="methodname">loadFunctions()</span> methods:
        </p>

        <pre class="programlisting brush: php">
...
/**
 * This function ...
 *
 * @param integer $inputParam
 * @return string
 */
function function1($inputParam) {
    ...
}

/**
 * This function ...
 *
 * @param integer $inputParam1
 * @param string  $inputParam2
 * @return float
 */
function function2($inputParam1, $inputParam2) {
    ...
}
...
$server = new Zend_Soap_Server(null, $options);
$server-&gt;addFunction(&#039;function1&#039;);
$server-&gt;addFunction(&#039;function2&#039;);
...
$server-&gt;handle();
</pre>

    </div>

    <div class="section" id="zend.soap.server.request_response"><div class="info"><h1 class="title">Request and response objects handling</h1></div>
        

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Advanced</b><br /></span>
            

            <p class="para">
                This section describes advanced request/response processing options and may be
                skipped.
            </p>
        </p></blockquote>

        <p class="para">
            <span class="classname">Zend_Soap_Server</span> component performs request/response processing
            automatically, but allows to catch it and do some pre- and post-processing.
        </p>

        <div class="section" id="zend.soap.server.request_response.request"><div class="info"><h1 class="title">Request processing</h1></div>
            

            <p class="para">
                 <span class="methodname">Zend_Soap_Server::handle()</span> method takes request from the
                standard input stream (&#039;php://input&#039;). It may be overridden either by supplying
                optional parameter to the  <span class="methodname">handle()</span> method or by setting
                request using  <span class="methodname">setRequest()</span> method:
            </p>

            <pre class="programlisting brush: php">
...
$server = new Zend_Soap_Server(...);
...
// Set request using optional $request parameter
$server-&gt;handle($request);
...
// Set request using setRequest() method
$server-&gt;setRequest();
$server-&gt;handle();
</pre>


            <p class="para">
                Request object may be represented using any of the following:

                <ul class="itemizedlist">
                    <li class="listitem">
                        <p class="para">
                            DOMDocument (casted to <acronym class="acronym">XML</acronym>)
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            DOMNode (owner document is grabbed and casted to <acronym class="acronym">XML</acronym>)
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            SimpleXMLElement (casted to <acronym class="acronym">XML</acronym>)
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            stdClass (__toString() is called and verified to be valid
                            <acronym class="acronym">XML</acronym>)
                        </p>
                    </li>

                    <li class="listitem">
                        <p class="para">
                            string (verified to be valid <acronym class="acronym">XML</acronym>)
                        </p>
                    </li>
                </ul>
            </p>

            <p class="para">
                Last processed request may be retrieved using
                 <span class="methodname">getLastRequest()</span> method as an <acronym class="acronym">XML</acronym>
                string:
            </p>

            <pre class="programlisting brush: php">
...
$server = new Zend_Soap_Server(...);
...
$server-&gt;handle();
$request = $server-&gt;getLastRequest();
</pre>

        </div>

        <div class="section" id="zend.soap.server.request_response.response"><div class="info"><h1 class="title">Response pre-processing</h1></div>
            

            <p class="para">
                 <span class="methodname">Zend_Soap_Server::handle()</span> method automatically emits
                generated response to the output stream. It may be blocked using
                 <span class="methodname">setReturnResponse()</span> with <b><tt>TRUE</tt></b> or
                <b><tt>FALSE</tt></b> as a parameter

                <a href="#fnid4" name="fn4"><sup>[4]</sup></a>
                     <span class="methodname">setReturnResponse()</span>
                .

                Generated response is returned by  <span class="methodname">handle()</span> method in this
                case.
            </p>

            <pre class="programlisting brush: php">
...
$server = new Zend_Soap_Server(...);
...
// Get a response as a return value of handle() method
// instead of emitting it to the standard output
$server-&gt;setReturnResponse(true);
...
$response = $server-&gt;handle();
...
</pre>


            <p class="para">
                Last response may be also retrieved by  <span class="methodname">getLastResponse()</span>
                method for some post-processing:
            </p>

            <pre class="programlisting brush: php">
...
$server = new Zend_Soap_Server(...);
...
$server-&gt;handle();
$response = $server-&gt;getLastResponse();
...
</pre>

        </div>
    </div>
<div class="footnote"><a name="fnid1" href="#fn1"><sup>[1]</sup></a><span class="para footnote">
                                    May be set later using 
                                    method.
                                </span></div>
<div class="footnote"><a name="fnid2" href="#fn2"><sup>[2]</sup></a><span class="para footnote">
                                    Options may be set later using
                                     method.
                                </span></div>
<div class="footnote"><a name="fnid3" href="#fn3"><sup>[3]</sup></a><span class="para footnote">
                        Options may be set later using 
                        method.
                    </span></div>
<div class="footnote"><a name="fnid4" href="#fn4"><sup>[4]</sup></a><span class="para footnote">
                        Current state of the Return Response flag may be requested with
                         method.
                    </span></div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.soap.html">Zend_Soap</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.soap.html">Zend_Soap</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.soap.client.html">Zend_Soap_Client</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.soap.html">Zend_Soap</a></li>
  <li class="active"><a href="zend.soap.server.html">Zend_Soap_Server</a></li>
  <li><a href="zend.soap.client.html">Zend_Soap_Client</a></li>
  <li><a href="zend.soap.wsdl.html">WSDL Accessor</a></li>
  <li><a href="zend.soap.autodiscovery.html">AutoDiscovery</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>